<template>
	<div class="mainCon panelsList">
		<div class="containercontent">
			<div class="selectw100 seachTip">
				<div class="inlineblock verticalmiddle infoitem">
					<div class="inlineblock verticalmiddle">
						能力参数
					</div>
					<div class="inlineblock verticalmiddle informationItem">
						<el-select v-model="detectability" filterable remote :remote-method="readDetectList" style="width:100%;" size="mini" ref="selectAbility"
						@change="getTestBatchs(testItemQuery,'search')">
							<el-option v-for="item in abilityOptions" :key="item.id" :label="'【' + item.version + '】' + item.name" :value="item.id">
							</el-option>
						</el-select>
					</div>
				</div>
        <div class="inlineblock verticalmiddle infoitem">
        	<div class="inlineblock verticalmiddle">
        		任务
        	</div>
        	<div class="inlineblock verticalmiddle informationItem">
        		<el-select v-model="task" filterable style="width:100%;" size="mini" @change="getTestBatchs(testItemQuery,'search')">
        			<el-option v-for="(item,index) in taskList" :key="item.index" :label="item" :value="item">
        			</el-option>
        		</el-select>
        	</div>
        </div>
				<div class="inlineblock verticalmiddle infoitem">
					<div class="inlineblock verticalmiddle">
						检测单筛选
					</div>
					<div class="inlineblock verticalmiddle informationItem">
						<el-select v-model="testValue" size="mini" @change="getTestBatchs(testItemQuery,'search')">
							<el-option v-for="item in testOptions" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-select>
					</div>
				</div>
				<div class="inlineblock verticalmiddle searchIcon" style="margin-left:15px;">

					<el-button size="mini" @click="getTestBatchs(testItemQuery,'search')">搜索</el-button>
				</div>
				<div class="inlineblock verticalmiddle searchIcon">
					<el-button size="mini" @click="emptySearch">清空</el-button>
				</div>

			</div>
			<div class="separaterowTable">
				<div class="tableTittle">
					<div><span class="fontImpact">1</span><span>检测列表</span></div>
				</div>
				<el-table :data="tableData" style="width: 100%" size="mini" class="tableCon entryTable" highlight-current-row
				 :cell-class-name="tableRowClassName">

					<el-table-column prop="pihao" label="单号" width="55px">
						<template slot-scope="scope">
								{{scope.$index+(testItemQuery.page - 1) * testItemQuery.pageCount + 1}}
						</template>
					</el-table-column>
					<el-table-column prop="code" label="检测单编号" min-width="110px" show-overflow-tooltip>
					</el-table-column>
					<el-table-column prop="detectabilityName" label="能力参数" min-width="170px" :show-overflow-tooltip = "true"></el-table-column>
					<el-table-column prop="taskNames" label="任务名称" min-width="170px" show-overflow-tooltip>
						<template slot-scope="scope">
							{{scope.row.taskNames == undefined ? '---':scope.row.taskNames}}
						</template>
					</el-table-column>
<!--
					<el-table-column prop="equipmentName" label="仪器" min-width="100px">
					</el-table-column>
					<el-table-column prop="assistEquipmentName" label="辅助仪器" min-width="100px">
					</el-table-column>-->
					<el-table-column prop="analystName" label="检测人员" min-width="70px">
					</el-table-column>
					<el-table-column prop="checkerName" label="校核人员" min-width="70px">
					</el-table-column>
					<!--<el-table-column prop="auditorName" label="审核人员" min-width="70px">
						<template slot-scope="scope">
								{{scope.row.auditorName == undefined ? '---' : scope.row.auditorName}}
						</template>
					</el-table-column>-->
					<el-table-column prop="status" label="状态" min-width="70px" :formatter="formatterStatus">
					</el-table-column>
					<el-table-column prop="updateTime" label="修改时间" width="130px" :formatter="formatterDate">
					</el-table-column>
					<el-table-column prop="caozuo" label="操作" min-width="130px">
						<template slot-scope="scope">
							<el-button @click="showresultentrypenal(scope.row)" type="text" size="small"  v-if = "userOpernation.update.display && !scope.row.doSub">数据录入</el-button>
							<!-- <el-button @click="showresultentrypenal(scope.row)" type="text" size="small"  :disabled="!scope.row.isDiff" v-if = "userOpernation.update.display && !scope.row.doSub">数据录入</el-button> -->
							<el-button @click="showSubEntry(scope.row)" type="text" size="small"  :disabled="!scope.row.isDiff" v-if = "userOpernation.update.display && scope.row.doSub">数据录入</el-button>
							<!--检测单重新进行检测安排-->
							<!--scope.row.status != 532 && -->
							<el-button type="text" size="small" @click="updateBatchStatus(scope.row)" v-if = "userOpernation.delete.display" :disabled = "scope.row.isRepeate">撤销</el-button>
						</template>
					</el-table-column>
				</el-table>
				<div class="block changepages">
					<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="testItemQuery.page" :page-sizes="[20,30,40]"
					 :page-size="testItemQuery.pageCount" layout="total, sizes, prev, pager, next, jumper" :total="rowNumber">
					</el-pagination>
				</div>
			</div>

		</div>
		<data-entry :addVisible.sync="resultentryshow" :testpanelData = "testpanelData" :selectData.sync="selectRow"></data-entry>
		<subDataEntry :addVisible.sync="subResultentry" :subTestpanelData.sync = "subTestpanelData" :subModel = "subModel"></subDataEntry>

	</div>
</template>

<script>
	import $ from 'jquery'
	import { mapState } from 'vuex'
	const dataEntry = () => import('./children/dataEntry.vue');
	const subDataEntry = () => import('./children/subDataEntry.vue');
	export default {
		data() {
			let that = this;
			return {
				userInfo: {},
				detectability: '', //搜索框能力参数绑定值
				abilityOptions: [], //能力参数选项
				tableData: [],
				testValue: 1, //检测筛选绑定值
				testItemQuery: { //分页信息
					page: 1,
					pageCount: 20
				},
				rowNumber:0,
				testOptions: [  //检测筛选选项
					{
						value: 1,
						label: '我的'
					},
					{
						value: 0,
						label: '全部'
					}
				],
        taskList:[],
        task:"",
				testpanelData:{}, //点击数据录入绑定的数据
				//结果录入的样品列表
				multipleSelection: [],
				resultentryshow: false,
				subResultentry:false, //分包的设置
				subTestpanelData:{},
				subModel:"myEntry",
        selectRow:{},

			}
		},
		watch: {
			// 监听分页变化
			testItemQuery: {
				handler(val, oldVal) {
					this.getTestBatchs(this.testItemQuery)
				},
				deep: true
			},
		},
		components: {
			 dataEntry,subDataEntry
		},
		mounted() {
			this.$store.dispatch('dogetDictionary')
			this.userInfo = JSON.parse(sessionStorage.getItem('laboratoryAccountInfo')); //获取存储的用户信息
			this.readTask();
      this.readDetectList('');
			this.getTestBatchs(this.testItemQuery);
		},
		computed: {
			...mapState(['testBatchStatus']),

		},
		props:['userOpernation'],
		methods: {
			// 处理时间
			formatterDate(row, column, cellValue) {
				if(cellValue == '' || cellValue == undefined || cellValue == null){
					return ''
				}else{
					return cellValue.substring(0, 16)
				}

			},
			// formatterTime(row, column) { //截取时间
			// 	return(row.factoryDate).substring(0, 10)
			// },
			// 处理状态
			formatterStatus(row, column, cellValue, index) {
				return this.util.changeStatus({ cellValue: cellValue, list: this.testBatchStatus })
			},
			 // 根据状态显示不同的颜色
            tableRowClassName({ row, column, rowIndex, columnIndex }) {
                // 2.草稿  4.已驳回  501.待签发 502.待检测 503.检测中 504.已完成

                if (row.status == '532' && columnIndex == 6) {
                    return "color1"
                }
            },
            //   搜索能力参数
            readTask(item) {
            	this.$http({
            		method: 'post',
            		apiUrl: '/detection/getBatchTasks.htm',
            		params: { status: '531' },
            		isJson: false
            	}).then(res => {
            		if (res.code == 0) {
            			this.taskList = res.data
            		}
            	})
            },
			//   搜索能力参数
			readDetectList(item) {
				this.$http({
					method: 'post',
					apiUrl: '/technology/readDetectList.htm',
					params: { name: item },
					isJson: false
				}).then(res => {
					if (res.code == 0) {
						this.abilityOptions = res.data
					}

				})
			},
			// 检测列表数据
			getTestBatchs(parp,search) {
				var analyst = '';
				if (this.testValue == '1') {
					analyst = this.userInfo.loginid
				} else {
					analyst = '';
				};
				var data = {
					detectability: this.detectability,
					analyst: analyst,
					group:1, //代表数据录入
					status: 531,
					reStatus:532,
          taskName:this.task
				};
				if(search !=undefined){
					this.testItemQuery.page = 1;
					data.page =  1;
					data.pageCount = parp.pageCount;
				}else{
					data.page =  parp.page;
					data.pageCount = parp.pageCount;
				}
				this.$http({
					method: 'post',
					apiUrl: '/detection/getTestBatchs.htm',
					params: data,
					isJson: true
				}).then(res => {
					if (res.code == 0) {
						this.tableData = res.data;
						if (!res.pageinfo) {
							this.rowNumber = 0;
						} else if (res.pageinfo && !res.pageinfo.rowNumber) {
							this.rowNumber = 0;
						} else {
							this.rowNumber = res.pageinfo.rowNumber;
						}
					}
				})
			},
			emptySearch() {  //清空数据
				this.detectability = '';
				this.testValue = 0;
        this.task = "";
				this.getTestBatchs(this.testItemQuery,'search')
			},
			showresultentrypenal(row) {
         this.selectRow = row;
				this.resultentryshow = true;
				// this.zujianDetectability = row.detectability;
				// this.rowId = row.id;

          this.$http({
          	method: 'post',
          	apiUrl: '/detection/getTestBatchAndItem.htm',
          	params: {
          		id: row.id
          	},
          	isJson: false
          }).then(res => {
          	if (res.code == 0) {
                this.testpanelData = res.data
          	}else{
          		this.resultentryshow = false;
          	}
          })


			},
			showSubEntry(row){
				this.$http({
					method: 'post',
					apiUrl: '/detection/getSubTestBatch.htm',
					params: {
						id: row.id
					},
					isJson: false
				}).then(res => {
					if (res.code == 0) {
						this.subTestpanelData = res.data
						this.subResultentry= true
						console.log(this.subTestpanelData)
					}
				})
			},
			// 撤销检测单
			updateBatchStatus(row){
				this.$set(row,'isRepeate',true)
				this.$confirm('是否撤销', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						method: 'post',
						apiUrl: '/detection/updateBatchStatus.htm',
						params: {id:row.id},
						isJson: false
					}).then(res => {
						this.$set(row,'isRepeate',false)
						if (res.code == 0) {
							this.$notify({
								type:"success",
								message:"撤销成功！",
								title:"成功"
							})
							this.getTestBatchs(this.testItemQuery);

						}
					})
				}).catch(() => {
					this.$set(row,'isRepeate',false)
					this.$message({
						type: 'info',
						message: '已取消撤销'
					});
				})},
			handleSizeChange: function (val) {
				this.testItemQuery.pageCount = val;
			},
			handleCurrentChange: function (val) {
				this.testItemQuery.page = val;
			},
		}
	}

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
	.entryTable .color1{
		color: #faa646
	}
  .panelsList .infoitem{
    width: calc(100%/4);
  }
</style>
